{% macro const(c) -%} {{c}}{{".0" if dbl else ""}} {%- endmacro %}
{% set reg_count_name = numbers[k - 1] %}
{% set arg_reg  = arg_regs[0] %}
/* Check for off-by-one errors in the George test. Make sure we don't coalesce
 * pseudo p into hardreg h if p has a neighbor whose degree is exactly k.
 * The test script validates that there are no spills - we shouldn't need to
 * spill any pseudos, but we'll be forced to spill if we coalesce a pseudo
 * into a hard register when we shouldn't.
 * NOTE: we don't have an equivalent off-by-one test for Briggs b/c it's
 * adequately covered by other tests.
 *
 * This test was generated from
 * templates/{{ self._TemplateReference__context.name }}.
 * */

#include "../util.h"

{{typ}} glob = {{const(0)}};

int target({{typ}} a) {

{% filter indent(width=4, first=true) %}{% filter comment_wrap %}
    // Make sure we don't coalesce a into {{arg_reg}}; this would fail the George test
    // because a's neighbor, one, has degree k.
    // First we define a clique of {{k}} registers, one-{{reg_count_name}}.
    // one interferes with a and has exactly {{k}} neighbors.
    // Once we prune a, we can prune one, then two-{{reg_count_name}}.
    // To avoid spilling, one must go in {{arg_reg}}, because two-{{reg_count_name}} all conflict with {{arg_reg}}.
    // If we coalesce a with {{arg_reg}}, we won't be able to prune one and we'll have
    // to spill something.
{% endfilter %}{% endfilter %}
    // NOTE - some of this is copy/pasted from twelve_regs_conflict.c.jinja;
    // it's just different enough that using the template arguably isn't worth
    // it.

    {{typ}} one = {{const(2)}} - a;
    {{typ}} two = one + one;
    {{typ}} three = {{const(2)}} + one;
    {{typ}} four = two * two;
    {{typ}} five = {{const(6)}} - one;
    {{typ}} six = two * three;
    {{typ}} seven = one + {{const(6)}};
    {{typ}} eight = two * {{const(4)}};
    {{typ}} nine = three * three;
    {{typ}} ten = four + six;
    {{typ}} eleven = {{const(16)}} - five;
    {{typ}} twelve = eleven + one;
{% if dbl %}
    double thirteen = five + eight;
    double fourteen = seven * two;
{% endif %}

    // save one to validate later/make it conflict with all the others
    glob = one;

    // validate others/make them conflict with {{arg_reg}}
    {% set args = ["1"] + numbers[1:k] + ["1"] %}
    {{- args | arg_wrap(validate_fn, ";", indent=4)}}

    // validate one
    check_one_{{typ}}(glob, {{const(1)}});
    return 0;
}
